package com.xiong.xtools.XToast;

import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.xiong.xtools.R;

import butterknife.BindView;

/**
 * Author : 熊文强
 * Time : 2017/9/20
 * Content : 自定义Toast
 */
public class ToastActivity extends AppCompatActivity implements View.OnClickListener {
	Button mButtonErrorToast;  // 错误的提示
	Button mButtonSuccessToast;  // 成功的提示
	Button mButtonInfoToast;  // 信息的提示
	Button mButtonWarningToast;  // 警告的提示
	Button mButtonNormalToastWoIcon;  // 普通的提示
	Button mButtonNormalToastWIcon;  // 带图标的普通提示
	private ToastActivity mContext;  // 初始化获取上下文

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_toast);
		mContext = ToastActivity.this;
		findView();
		initEvent();
	}

	private void initEvent() {
		mButtonErrorToast.setOnClickListener(this);
		mButtonSuccessToast.setOnClickListener(this);
		mButtonInfoToast.setOnClickListener(this);
		mButtonWarningToast.setOnClickListener(this);
		mButtonNormalToastWoIcon.setOnClickListener(this);
		mButtonNormalToastWIcon.setOnClickListener(this);
	}

	private void findView() {
		mButtonErrorToast = (Button) findViewById(R.id.button_error_toast);
		mButtonSuccessToast = (Button) findViewById(R.id.button_success_toast);
		mButtonInfoToast = (Button) findViewById(R.id.button_info_toast);
		mButtonWarningToast = (Button) findViewById(R.id.button_warning_toast);
		mButtonNormalToastWoIcon = (Button) findViewById(R.id.button_normal_toast_wo_icon);
		mButtonNormalToastWIcon = (Button) findViewById(R.id.button_normal_toast_w_icon);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()){
			case R.id.button_error_toast:
				RxToast.error(mContext, "这是一个提示错误的Toast！", Toast.LENGTH_SHORT, true).show();
				break;
			case R.id.button_success_toast:
				RxToast.success(mContext, "这是一个提示成功的Toast!", Toast.LENGTH_SHORT, true).show();
				break;
			case R.id.button_info_toast:
				RxToast.info(mContext, "这是一个提示信息的Toast.", Toast.LENGTH_SHORT, true).show();
				break;
			case R.id.button_warning_toast:
				RxToast.warning(mContext, "这是一个提示警告的Toast.", Toast.LENGTH_SHORT, true).show();
				break;
			case R.id.button_normal_toast_wo_icon:
				RxToast.normal(mContext, "这是一个普通的没有ICON的Toast").show();
				break;
			case R.id.button_normal_toast_w_icon:
				Drawable icon = getResources().getDrawable(R.mipmap.ic_set);
				RxToast.normal(mContext, "这是一个普通的包含ICON的Toast", icon).show();
				break;
		}
	}
}
